package com.singleton;

public class Singleton {
    //1.构造函数私有化
    private Singleton(){}
    //2. 静态字段引用唯一实例:
    private static final Singleton INSTANCE=new Singleton();
    //3.通过静态方法来获取
    public static Singleton getInstance(){
        return INSTANCE;
    }
}

class test1{
    public static void main(String[] args) {
//        System.out.println(Singleton.INSTANCE.hashCode());
//        System.out.println(Singleton.INSTANCE.hashCode());
//        System.out.println(Singleton.INSTANCE.hashCode());
//        System.out.println(Singleton.INSTANCE.hashCode());
        System.out.println(Singleton.getInstance().hashCode());
        System.out.println(Singleton.getInstance().hashCode());
        System.out.println(Singleton.getInstance().hashCode());
        System.out.println(Singleton.getInstance().hashCode());
    }
}
